package com.hbisedm.interninfosys.utils;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author Sam
 */
public class MenuChangeUtil {
    public static List<String> getCurrentRole() {
        ArrayList<String> resultArr = new ArrayList<>();
        Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
        for (GrantedAuthority authority : authorities) {
            String authority1 = authority.getAuthority();
            String result = authority1.substring(5);
            resultArr.add(result);
        }
        return resultArr;
    }

    public static String getCurrentName() {
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        return name;
    }
}
